home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / window3a / palette3.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-23  |  4.1 KB  |  135 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Windows Colours by oigres P"
  4.    ClientHeight    =   4155
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   6375
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   277
  10.    ScaleMode       =   3  'Pixel
  11.    ScaleWidth      =   425
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.PictureBox Picture1 
  14.       AutoRedraw      =   -1  'True
  15.       AutoSize        =   -1  'True
  16.       Height          =   3855
  17.       Left            =   2400
  18.       ScaleHeight     =   253
  19.       ScaleMode       =   3  'Pixel
  20.       ScaleWidth      =   45
  21.       TabIndex        =   4
  22.       Top             =   120
  23.       Width           =   735
  24.    End
  25.    Begin VB.CommandButton Command5 
  26.       Caption         =   "Randomize Element"
  27.       Height          =   495
  28.       Left            =   0
  29.       TabIndex        =   3
  30.       Top             =   720
  31.       Width           =   1095
  32.    End
  33.    Begin VB.ListBox List1 
  34.       Height          =   2790
  35.       Left            =   3480
  36.       TabIndex        =   2
  37.       Top             =   120
  38.       Width           =   2655
  39.    End
  40.    Begin VB.CommandButton Command3 
  41.       Caption         =   "Restore"
  42.       Height          =   495
  43.       Left            =   0
  44.       TabIndex        =   1
  45.       Top             =   1320
  46.       Width           =   1095
  47.    End
  48.    Begin VB.CommandButton Command1 
  49.       Caption         =   "Randomize All Colours"
  50.       Height          =   495
  51.       Left            =   0
  52.       TabIndex        =   0
  53.       Top             =   120
  54.       Width           =   1095
  55.    End
  56. Attribute VB_Name = "Form1"
  57. Attribute VB_GlobalNameSpace = False
  58. Attribute VB_Creatable = False
  59. Attribute VB_PredeclaredId = True
  60. Attribute VB_Exposed = False
  61. 'Windows Colours by oigres P
  62. 'Email: oigres@postmaster.co.uk
  63. 'Adapted from MSDN :indented by indenter5
  64. Const COLOR_BACKGROUND = 1
  65. Const COLOR_ACTIVECAPTION = 2
  66. Const COLOR_WINDOWFRAME = 6
  67. Const clr As Integer = 255
  68. Dim SavedColors(clr) As Long
  69. Sub Command1_Click()
  70.     Dim i As Long
  71.     ' Change all display elements:
  72.     ReDim NewColors(clr) As Long
  73.     ReDim IndexArray(clr) As Long
  74.     For i = 0 To clr
  75.         NewColors(i) = QBColor(Int(16 * Rnd))
  76.         IndexArray(i) = i
  77.     Next i
  78.     SetSysColors clr + 1, IndexArray(0), NewColors(0)
  79. End Sub
  80. Private Sub Command3_Click()
  81.     Dim i As Long
  82.     ' Restore system colors:
  83.     ReDim IndexArray(clr) As Long
  84.     For i = 0 To clr
  85.         IndexArray(i) = i
  86.     Next i
  87.     SetSysColors clr + 1, IndexArray(0), SavedColors(0)
  88.     picupdate
  89. End Sub
  90. Private Sub Command5_Click()
  91.     If List1.ListIndex > -1 Then
  92.         SetSystemPaletteUse Form1.hdc, SYSPAL_NOSTATIC
  93.         mydc = GetDC(Form1.hwnd)
  94.         oldmode = SetBkMode(mydc, TRANSPARENT)
  95.         SetSysColors 1, List1.ListIndex, QBColor(Int(16 * Rnd))
  96.         SetBkMode mydc, oldmode
  97.         ReleaseDC Form1.hwnd, mydc
  98.         SetSystemPaletteUse Form1.hdc, SYSPAL_STATIC
  99.         picupdate
  100.     End If
  101. End Sub
  102. Sub Form_Load()
  103.     Dim i As Long
  104.     ' Save current system colors:
  105.     For i = 0 To clr
  106.         SavedColors(i) = GetSysColor(i)
  107.         List1.AddItem i & ":" & Hex(SavedColors(i))
  108.     Next i
  109.     Show
  110.     picupdate 'draw colours into picbox
  111. End Sub
  112. Sub picupdate()
  113.     'set up pic display
  114.     Picture1.CurrentX = 0
  115.     Picture1.CurrentY = 0
  116.     i = 0
  117.     For Y = 0 To Picture1.ScaleHeight Step Picture1.ScaleHeight \ 24
  118.         Picture1.CurrentX = 0
  119.         Picture1.CurrentY = Y
  120.         Picture1.Print i
  121.         Picture1.Line (18, Y)-(Picture1.ScaleWidth, Y + 8), GetSysColor(i), BF
  122.         i = i + 1
  123.     Next
  124. End Sub
  125. Private Sub Form_Unload(Cancel As Integer)
  126.     'set colours back to original then exit program correctly
  127.     'if you don't unload form then colours not restored
  128.     Command3.Value = True
  129.     Unload Me
  130.     Set Form1 = Nothing
  131. End Sub
  132. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  133.     Picture1.ToolTipText = Hex(Picture1.Point(X, Y))
  134. End Sub
  135.